package com.ruoyi.aisite.controller;

import com.ruoyi.aisite.domain.AiPage;
import com.ruoyi.aisite.service.IAiPageService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * AI页面Controller
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/aisite/page")
public class AiPageController extends BaseController {
    private String prefix = "aisite/page";

    @Autowired
    private IAiPageService aiPageService;

    @GetMapping()
    public String page() {
        return prefix + "/page";
    }

    /**
     * 查询AI页面列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AiPage aiPage) {
        startPage();
        List<AiPage> list = aiPageService.selectAiPageList(aiPage);
        return getDataTable(list);
    }

    /**
     * 新增AI页面
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存AI页面
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AiPage aiPage) {
        return toAjax(aiPageService.insertAiPage(aiPage));
    }

    /**
     * 修改AI页面
     */
    @GetMapping("/edit/{pageId}")
    public String edit(@PathVariable("pageId") Long pageId, ModelMap mmap) {
        AiPage aiPage = aiPageService.selectAiPageById(pageId);
        mmap.put("aiPage", aiPage);
        return prefix + "/edit";
    }

    /**
     * 修改保存AI页面
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AiPage aiPage) {
        return toAjax(aiPageService.updateAiPage(aiPage));
    }

    /**
     * 删除AI页面
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(aiPageService.deleteAiPageByIds(Convert.toLongArray(ids)));
    }
}